package com.scoy.honeymei.wxapi;

import android.app.Activity;

import com.google.gson.Gson;
import com.lzy.okgo.model.HttpParams;
import com.scoy.honeymei.http.HpCallback;
import com.scoy.honeymei.http.HpGo;
import com.scoy.honeymei.url.MyUrl;
import com.scoy.honeymei.utils.MyUtil;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @ClassName: PayUtil$
 * @Description:
 * @Author: GaoZhan
 * @CreateDate: 2019/9/12/0012$ 上午 10:49$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/9/12/0012$ 上午 10:49$
 * @UpdateRemark: 更新内容
 */
public class PayUtil {

    public static void toPayPayPay(Activity mContext, int payType, String o) {//1=支付宝、2=微信、3=观影券
        if (payType == 1) {
            FastPay.create(mContext).aliPay(o);
        } else if (payType == 2) {
            WechatBean wePayBean = new Gson().fromJson(o, WechatBean.class);
            IWXAPI api = WXAPIFactory.createWXAPI(mContext, wePayBean.getAppid());
            api.registerApp(wePayBean.getAppid());
            PayReq payReq = new PayReq();
            payReq.appId = wePayBean.getAppid();
            payReq.partnerId = wePayBean.getPartnerid();  //  商户号
            payReq.packageValue = "Sign=WXPay";
            payReq.prepayId = wePayBean.getPrepayid();
            payReq.nonceStr = wePayBean.getNoncestr();
            payReq.timeStamp = wePayBean.getTimestamp();
            payReq.sign = wePayBean.getSign();
            api.sendReq(payReq);
        } else if (payType == 3) {
            MyUtil.mytoast(mContext, "支付成功");
        }
    }

    public static void toPayPayPay(Activity mContext, String payType, String o) {
        if ("alipay".equals(payType)) {
            FastPay.create(mContext).aliPay(o);
        } else if ("wechat".equals(payType)) {
            WechatBean wePayBean = new Gson().fromJson(o, WechatBean.class);
            IWXAPI api = WXAPIFactory.createWXAPI(mContext, wePayBean.getAppid());
            api.registerApp(wePayBean.getAppid());
            PayReq payReq = new PayReq();
            payReq.appId = wePayBean.getAppid();
            payReq.partnerId = wePayBean.getPartnerid();  //  商户号
            payReq.packageValue = "Sign=WXPay";
            payReq.prepayId = wePayBean.getPrepayid();
            payReq.nonceStr = wePayBean.getNoncestr();
            payReq.timeStamp = wePayBean.getTimestamp();
            payReq.sign = wePayBean.getSign();
            api.sendReq(payReq);
        } else if ("balance".equals(payType)) {

        }
    }


/*

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onPayEvent(PayEvent event) {
       //todo
    }

    @Override
    public void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);
    }

*/

}
